/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode *addTwoNumbers(ListNode *l1, ListNode *l2) {
        int g=0;
        ListNode ret(-1), *tail=&ret;
        while (l1 || l2 || g){
            g+=((l1==NULL)?0:l1->val)+((l2==NULL)?0:l2->val);
            if (l1!=NULL) l1=l1->next;
            if (l2!=NULL) l2=l2->next;
            tail->next=new ListNode(g%10);
            tail=tail->next;
            g/=10;
        }
        return ret.next;
    }
};
